"""
class 父类:
    pass
class 子类(父类):
    pass
"""
"""
class Parent1:
    xxx = 333
    def run(self):
        print("我是父类的方法")
class Sub(Parent1):
    xxx = 666
    def run(self):
        print("我是子类的方法")
    pass
"""
# 通过Sub类创建s1对象
# s1 = Sub()
# 调用方法可以使用父类的
# s1.run()
# 子类可以使用父类的类属性
# print(s1.xxx) # 333
"""
子类没有这个方法的时候，会执行到父类方法
子类没有类属性的时候，会使用到父类的类属性
    
子类 > 父类
"""

# 创建基类，让子类继承父类
"""
class People:
    school = "不造啊"
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student(People): # Student类继承People类
    def play(self):
        print("%s play football" % self.name)
class Teacher(People): # Teacher类继承Peple类
    def course(self):
        print("%s course"%self.name)
# 实例化的时候，子类有__init__方法，会走到父类的
s1 = Student("张三",19,'男')
print(s1.__dict__)  # 打印对象属性
t1 = Teacher("张鑫",89,"女")
print(t1.__dict__) # {'name': '张鑫', 'age': 89, 'sex': '女'}
"""

# 但是这里有个问题子类有新的属性需要实例化的时候参数怎么办
# 可以使用子类派生方法
"""
子类重用父类的功能
在子类派生出的新方法中重用父类功能的方式一：
指名道姓的引用某一个类中的函数
"""
"""
class People:
    school = "不造啊"
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student():
    def __init__(self,name,age,sex,score = 0):
        # self.name = name
        # self.age = age
        # self.sex = sex
        People.__init__(self,name,age,sex)
        self.score = score
    def play(self):
        print("%s play football"%self.name)
class Teacher():
    def __init__(self , name, age,sex,hobby):
        self.hobby = hobby
        People.__init__(self,name,age,sex)
    def course(self):
        print("%s course"%self.name)
# 通过Student类创建对象
stu1 = Student("张三",19,'男',100)
print(stu1.__dict__) # 打印它的实例属性 {'name': '张三', 'age': 19, 'sex': '男', 'score': 100}
# 通过Teacher类创建对象
t1 = Teacher("张鑫",96,"女","打羽毛球")
print(t1.__dict__) # {'hobby': '打羽毛球', 'name': '张鑫', 'age': 96, 'sex': '女'}
"""

# 在子类派生的新方法中重用父类功能的方式二
"""
派生实例化除了父类的属性添加，还能有自己的独有属性
在子类派生出的新方法中重用父类的功能方式二：super() 必须在类中使用
super(自己的类名,自己的对象)
可以省略船只
super()
"""
"""
class People:
    school = "不造啊"
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student(People):
    def __init__(self,name,age,sex,score = 0):
        super(Student,self).__init__(name,age,sex)
        self.score = score
    def play(self):
        print("%s play football"%self.name)
class Teacher(People):
    def __init__(self,name,age,sex,hobby):
        super().__init__(name,age,sex)
        self.hobby = hobby
    def course(self):
        print("%s course"%self.name)
# 根据Student类创建对象
stu1 = Student("张三",19,"男",100)
print(stu1.__dict__) # {"name":"张三","age":19,"sex":"男","score":100}
# 根据Teacher类创建对象
tea1 = Teacher("张鑫",100,"女","打羽毛球")
print(tea1.__dict__) # {'name': '张鑫', 'age': 100, 'sex': '女', 'hobby': '打羽毛球'}
"""
# 在单继承背景下的属性查找
"""
在单继承背景下属性的查找优先级：对象->对象的类->父类->父类....->object
"""
"""
class Foo(object):
    xxx = 444
    pass
class Bar1(Foo):
    # xxx = 333
    pass
class Bar2(Bar1):
    # xxx = 222
    pass
"""
"""
Foo：爷爷
Bar1：爸爸
Bar2：儿子/孙子
"""
# 通过Bar2创建对象
"""
bar2 = Bar2()
print(bar2.xxx) # 222
print(type(bar2)) #<class '__main__.bar2'>
"""

#
# print(str)
# print(list)
# print(tuple)
# print(set)
# print(dict)

# 万物皆是对象
# print(type("aaa")) # <class 'str'>

# 在多继承背景下的属性查找
"""
在多继承背景下属性的查找优先级：
此时属性的查找优先级是：对象->对象的类->按照从左往右的顺序一个分支一个分支的找下去
广度优先查找，从左往右一个分支一个分支的查找，在最后一个分支下才去查找顶级类
"""
class G():
    x = 'G'
    pass
class E(G):
    # x = 'E'
    pass
class F(G):
    # x = 'F'
    pass
class B(E):
    # x = 'B'
    pass
class C(F):
    # x = 'C'
    pass
class D(G):
    # x = 'D'
    pass
class A(B,C,D):
    # x = 'A'
    pass
# 通过A创建对象
a = A()
print(a.x)

print(A.mro())























































